
import { BrowserRouter, Route, Routes, Navigate } from "react-router-dom";
import { ControllerRoot, SystemController } from "@/controllers";
import { themeConfig } from "@/constant";
import { ConfigProvider } from "antd";
import zhCN from 'antd/locale/zh_CN';
import { DevButton } from "./views/Development";
import * as views from "@/views";
import React from "react";
import 'dayjs/locale/zh-cn';

export default function App() {
  return (
    <ConfigProvider locale={zhCN} theme={themeConfig} >
      <ControllerRoot>
        <DevButton />
        <AppRouter />
      </ControllerRoot>
    </ConfigProvider>
  )
}

function AppRouter() {

  const token = React.useContext(SystemController.Context)?.useMemo(s => s.token);

  return (
    <BrowserRouter>
      <Routes>
        {import.meta.env.MODE === 'development' && <Route key={'dev'} path='/dev/*' element={<views.Development />} />}
        {
          token
            ? <>
              <Route key='layout' path='/*' element={<views.Layout />} />
              <Route key='e404' path='*' element={<Navigate to='/' />} />
            </>
            : <Route key={'login'} path='*' element={<views.Login />} />
        }
      </Routes>
    </BrowserRouter>
  )
}

